let ipt1 = document.querySelector('#ipt1')
let ipt2 = document.querySelector('#ipt2')
let btn = document.querySelector('#btn')
let ems = document.querySelectorAll('em')

// 正则验证手机号，也是用户名
ipt1.onblur = function() {
    let g = ipt1.value;
    let i = /([a-zA-Z]|[\u2e80-\u9FFF]|[0-9]){1,8}$/;
    if (i.test(g) == false) {
        ems[0].innerHTML = '账号格式错误'
        ipt1.style.border = "1px solid #ff6700"
    } else {
        ems[0].innerHTML = ''
        ipt1.style.border = "1px solid #e8e8e8"
    }
}

// 判断用户名是否可用
ipt1.onchange = function() {
    let username = ipt1.value
    axios.get(inquireAPI, {
        params: {
            username
        }
    }).then(res => {
        // console.log(res);//返回的数据
        console.log(res.data.msg);
    })
}

// 正则验证密码格式
ipt2.onblur = function() {
    let g = ipt2.value;
    let i = /^[a-zA-Z0-9_-]{3,16}$/;
    if (i.test(g) == false) {
        ems[1].innerHTML = '密码格式错误'
        ipt2.style.border = "1px solid #ff6700"
    } else {
        ems[1].innerHTML = ''
        ipt2.style.border = "1px solid #e8e8e8"
    }
}
//请求接口，注册用户
btn.onclick = function() {
    let username = ipt1.value
    let password = ipt2.value
    let params = {
        username,
        password,
    };
    axios.get(regAPI, {
        params
    }).then(res => {
        // console.log(res);//返回的数据
        alert(res.data.msg);
        if (res.data.code == 1) {
            location.href = "logoin.html";
        }
    })
}
let ipt = document.querySelector('.ipt')
let iptb = document.querySelector('.ipt-b')
let iptp = document.querySelectorAll('.ipt-b p')
let iptspan = document.querySelector('.ipt span')
//下拉菜单
flag= false;
 ipt.onclick=function(){
     if (flag) {
        iptb.style.display = "none"
        flag= false;
     }else{
        iptb.style.display = "block"
        flag= true;
     }
 };
 iptp.forEach(v => {
   v.onclick=function(){
    iptspan.innerHTML=this.innerHTML
    iptb.style.display = "none"
   }
 });

 //密码显示和隐藏
 let passwordshow = document.querySelector("#yj")
//  console.log(passwordshow);
//  console.log(ipt2);
 yjl = false
 passwordshow.onclick=function(){
     if (yjl) {
        ipt2.type ="password"
        yjl = false
     }else{
        ipt2.type ="text"
        yjl = true
     }
 }